//
//  RNOLMyInvestSubViewController.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/27.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLMyInvestSubViewController.h"
#import "RNOLMeInvestHeaderView.h"

@interface RNOLMyInvestSubViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSArray *dataSource;

@end

@implementation RNOLMyInvestSubViewController

- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , self.view.height) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = kBgColor;
        adjustsScrollViewInsets_NO(_tableView, self);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 60;
        UIView *headerBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , 160)];
        headerBg.backgroundColor = KWhiteColor;
        RNOLMeInvestHeaderView *header = [RNOLMeInvestHeaderView FromXIB];
        header.frame = headerBg.bounds;
        [headerBg addSubview: header];
        
        _tableView.tableHeaderView = headerBg;
        _tableView.tableFooterView = [UIView new];
        [self.view addSubview: _tableView];
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kBgColor;
    [self setupNavBarTitleViewWithText:@"我的投资"];
    [self setup];
}


- (void)setup{
    self.dataSource = @[@"所有项目",@"已款中的项目",@"已还款的项目"];
    [self.tableView reloadData];
}

#pragma mark -  UITableViewDelegate && UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text = self.dataSource[indexPath.row];
    cell.textLabel.textColor = kTextColor;
    cell.textLabel.font = KFontSize(15);
    return cell;
}

- (void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *title = self.dataSource[indexPath.row];
    if (kCompareTwoString(title, @"所有项目")) {

    }else if (kCompareTwoString(title, @"已款中的项目")) {
        
    }else if (kCompareTwoString(title, @"已还款的项目")) {

    }
}


@end
